package info.liujiachen.security.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@SpringBootApplication
@RestController
public class CORSApiLoginApp {

    @RequestMapping("/api/user")
    public String user() {
        return "user";
    }

    @RequestMapping("/api/admin")
    public String admin() {
        return "admin";
    }

    @RequestMapping("/api/login/success")
    public String loginSuccess() {
        return "success";
    }

    @RequestMapping("/api/login/error")
    public String loginError() {
        return "error";
    }

    @RequestMapping("/error")
    public String loginError(HttpServletRequest request) {
        int code = (int) request.getAttribute("javax.servlet.error.status_code");
        switch (code) {
            case 403:
                return "No Permission";
            case 404:
                return "Not Found";
            case 500:
                return "System exception";
            default:
                return "Unknown";
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(CORSApiLoginApp.class, args);
    }

}
